package com.antler.smt.admin.controller;

import com.antler.smt.admin.mapper.DictionaryEntityMapper;
import com.antler.smt.admin.mapper.DictionaryInfoMapper;
import com.antler.smt.entity.DictionaryEntity;
import com.antler.smt.request.admin.DictionaryListReq;
import com.antler.smt.request.admin.DictionaryUpdateReq;
import com.antler.smt.response.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * TODO
 *
 * @author vic
 * @date 2018-04-11 22:44
 *  
 */
@RestController
@RequestMapping(value = "/dictionary")
@Api(description = "字典接口")
public class DictionaryController {

    @Autowired
    DictionaryInfoMapper dictionaryInfoMapper;

    @Autowired
    DictionaryEntityMapper dictionaryEntityMapper;

    /**
     * 字典列表
     *
     * @param request
     * @return
     */
    @GetMapping("/listDictionary")
    @ApiOperation(value = "字典列表", httpMethod = "GET")
    public Result listDictionary(DictionaryListReq request) {
        List<DictionaryEntity> dictionaryEntityList = dictionaryInfoMapper.searchDictionary(request);
        return new Result(dictionaryEntityList);
    }

    /**
     * 字典列表
     *
     * @param request
     * @return
     */
    @PostMapping("/updateDictionary")
    @ApiOperation(value = "更新字典", httpMethod = "POST")
    public Result updateDictionary(@RequestBody DictionaryUpdateReq request) {

        DictionaryEntity dictionaryEntity = dictionaryEntityMapper.selectByPrimaryKey(request.getId());
        dictionaryEntity.setdValue(request.getValue());
        dictionaryEntity.setUpdateTime(new Date());
        dictionaryEntityMapper.updateByPrimaryKey(dictionaryEntity);
        return new Result();
    }
}
